# encoding=utf-8
from seg_system.LongTaskStatusUpload.IStatusUpload import IStatusUpload


class MultiStatusUploadImpl(IStatusUpload):
    """2022-08_06_数据处理记录, 急任务，此代码需要大量修正
    """
    d = {
        'state': 'System Predict Start!!!',
        'file_name': 'wait input',
        'has_finished': False
    }

    def get_info_struct(self):
        return MultiStatusUploadImpl.d

    def init_struct(self, redis_key: str, **kwargs):
        self.all_redis.key_set_dict(redis_key, MultiStatusUploadImpl.d)
        return True

    def update_state(self, redis_key: str, state, **kwargs):
        d = self.all_redis.key_get(redis_key)
        d['state'] = state
        self.all_redis.key_set_dict(redis_key, d)
        return True

    def update_current(self, redis_key: str, name: str, count: int = 0, **kwargs):
        d = self.all_redis.key_get(redis_key)
        d['file_name'] = name
        self.all_redis.key_set_dict(redis_key, d)
        return True

    def update_total(self, redis_key: str, count: int = 0, **kwargs):
        has_finished = kwargs.get('has_finished', False)
        d = self.all_redis.key_get(redis_key)
        d['has_finished'] = has_finished
        self.all_redis.key_set_dict(redis_key, d)
        return True

    def update_seq(self, redis_key: str, **kwargs):
        """这里描述的是清空流程
        """
        self.all_redis.key_remove(redis_key)
        self.update_state(redis_key, "System Predict Start!!!")
        self.update_total(redis_key, has_finished=False)

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_inst'):
            cls._inst = super(MultiStatusUploadImpl, cls).__new__(cls)
        return cls._inst